﻿using System;
using System.Diagnostics;
using System.IO;

namespace HmLab;

internal class LbResolveEnvirPath {
  public class Resolver(LbResolveEnvirPath _impl) {
    public AppEnvPath Resolve(string resDir, string inDir) => _impl.ResolveImpl(resDir, inDir);
  }

  /// <summary>
  /// <see cref="Haimen.AppEnvResolver"/>
  /// </summary>
  public void Run() {
    string resDir = @"E:\work_etc\nina\2023haimen2\workshop_cs\haimen\resources";
    string inDir = @"E:\work_etc\nina\2023haimen2\workshop_cslab\输O入test";
    AppEnvPath envPath = ResolveImpl(resDir, inDir);

    string lookupPath = ResolveLookupPath(envPath);
    Debug.Assert(File.Exists(lookupPath));
    Console.WriteLine(lookupPath);
  }

  AppEnvPath ResolveImpl(string resDir, string inDir, string outDir = "") {
    return new(resDir, inDir, outDir);
  }

  /// <summary>
  /// <see cref="Haimen.Func1.HuallExportMerger"/>
  /// </summary>
  string ResolveLookupPath(AppEnvPath path) {
    const string lookup = "vlookup.xlsx";
    string dev = path.InDev(lookup);

    if (!File.Exists(dev)) {
      return path.ResFunc1(lookup);
    }
    Console.WriteLine($"检测到dev：{dev}");
    return dev;
  }
}

internal record AppEnvPath(string Res, string In, string Out) {
  public string ResFunc1(string path) => Path.Join(Res, "func1", path);
  public string InDev(string path) => Path.Join(In, "dev", path);
}
